import { useEffect, useRef, useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'

function App() {
  const [count, setCount] = useState(0);

  const [height, setHeight] = useState(0);

  const AppRef = useRef<HTMLElement>(null);

  useEffect(() => {
    setHeight(AppRef.current?.getClientRects()?.[0]?.height || 0)
  }, [])

  return (
    <section ref={AppRef} className='App' style={{ height: `calc(${window.innerHeight}px - 2px)` }}>
      <div>
        <p>AppDomHeight: {height}</p>
        <p>innerHeight: {window.innerHeight}</p>
        <p>screen.height: {window.screen.height}</p>
      </div>
      
      <div>
        <a href="https://vite.dev" target="_blank">
          <img src={viteLogo} className="logo" alt="Vite logo" />
        </a>
        <a href="https://react.dev" target="_blank">
          <img src={reactLogo} className="logo react" alt="React logo" />
        </a>
      </div>
      <h1>Vite + React</h1>
      <div className="card">
        <button onClick={() => setCount((count) => count + 1)}>
          count is {count}
        </button>
        <p>
          Edit <code>src/App.tsx</code> and save to test HMR
        </p>
      </div>
      {
        [...Array(40).keys()].map(i => <p>index: {i}</p>)
      }

      <div className="test-fix">fixed-bottom</div>
    </section>
  )
}

export default App
